import os
total_size = 0
def data_size(data_name):
    global total_size
    data_list = os.listdir(data_name)
    print(data_list)
    for data in data_list:
        data_path = os.path.join(data_name, data)
        print(data_path)
        if os.path.isfile(data_path):
            datasize = os.path.getsize(data_path)
            print(datasize)
            total_size += datasize
        else:
            data_size(data_path)
data_size('d://Users//Desktop//测试文件')
print('目录总大小为%d字节' % total_size)
